import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { FlyFootBmp } from "../mapUI/flyFoot/FlyFootBmp";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { AIManager } from "../../scene/ai/AIManager";
import { AIType } from "../../scene/ai/AIType";
import { SPlantFlowerInfo } from "../../../../Message/Game/SPlantFlowerInfo";
import { BossConfig } from "../../resource/BossConfig";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
import { MapIdRule } from "../../rules/MapIdRule";
import { EntityType } from "../../rules/EntityType";
import { TBoss } from "../../../../Message/Db/Tables/TBoss";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
//class MyPlantLightView
    
    export  class MyPlantLightView extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.uiLayer;
            this.mouseEnabled = false;
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            this._unMouseSp = new Object /* flash.display.Sprite */();
            this._unMouseSp.mouseEnabled = false;
            this._unMouseSp.mouseChildren = false;
            this.addChild(this._unMouseSp);
            this._myLightBless = ObjCreate.createGTextField("", 60, 10, 100, 20, this._unMouseSp, GlobalStyle.textFormat2);
            this._myLight = ObjCreate.createGTextField("", 80, 53, 100, 20, this, GlobalStyle.textFormat6);
            this._myLight.htmlText = "<a href=\'event:\'><u>" + Language.getString(69829) + "</u></a>";
            this._myLight.addEventListener(flash.events.TextEvent.LINK, this.onMyLightLinkClick);
            this._flyBoot = new FlyFootBmp();
            this._flyBoot.x = this._myLight.x + this._myLight.textWidth + 5;
            this._flyBoot.y = this._myLight.y;
            this._flyBoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyBootClickHandler);
            this.addChild(this._flyBoot);
            LoaderHelp.addResCallBack(ResFileConst.plantFlower, this.updateBitmapData);
            return;
        }

        /* internal  */updateBitmapData(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.PlantLightBg);
            loc1.x = 44;
            loc1.y = 28;
            this._unMouseSp.addChildAt(loc1, 0);
            this._process = GlobalClass.getBitmap(ImagesConst.PlantLightProgress);
            this._process.x = 50;
            this._process.y = 35;
            this._unMouseSp.addChild(this._process);
            this._processMask = new Object /* flash.display.Shape */();
            this._unMouseSp.addChild(this._processMask);
            this._process.mask = this._processMask;
            this._processHead = GlobalClass.getBitmap(ImagesConst.PlantLightProgressHead);
            this._processHead.x = 50;
            this._processHead.y = 17;
            this._unMouseSp.addChild(this._processHead);
            loc1 = GlobalClass.getBitmap(ImagesConst.PlantLightLeft);
            loc1.x = 20;
            loc1.y = 12;
            this._unMouseSp.addChild(loc1);
            this.updateProcess();
            return;
        }

        /* internal  */onMyLightLinkClick(arg1): void
        {
            if (this._target) 
            {
                AIManager.onAutoPathAIControl(this._target);
            }
            return;
        }

        /* internal  */onFlyBootClickHandler(arg1): void
        {
            if (this._target) 
            {
                AIManager.onAIControl(this._target, AIType.AI_Convey);
            }
            return;
        }

        public updateMyLightState(arg1: SPlantFlowerInfo): void
        {
            this._boss = BossConfig.instance.getInfoByName(arg1.bossId);
            if (!this._target) 
            {
                this._target = new TaskTargetInfo();
            }
            this._target.x = arg1.point.x;
            this._target.y = arg1.point.y;
            this._target.mapId = MapIdRule.TaijiCity;
            this._target.id = arg1.bossId;
            this._target.targetType = EntityType.Boss;
            var loc1=arg1.hadBlessPlayers.length + arg1.autoBlessNum;
            this._myLightBless.htmlText = Language.getString(69817) + ": " + loc1 + "/" + this._boss.maxMana;
            this._processNum = loc1 / this._boss.maxMana;
            this.updateProcess();
            return;
        }

        /* internal  */updateProcess(): void
        {
            if (this._processMask) 
            {
                this._processMask.graphics.clear();
                this._processMask.graphics.beginFill(16777215, 1);
                this._processMask.graphics.drawRect(this._process.x, this._process.y, this._process.width * this._processNum, this._process.height);
                this._processMask.graphics.endFill();
                this._processHead.x = this._process.x + this._processMask.width - 20;
            }
            return;
        }

        /* internal */ /* var */_target: TaskTargetInfo;

        /* internal */ /* var */_boss: TBoss;

        /* internal */ /* var */_unMouseSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_myLightBless: GTextFiled;

        /* internal */ /* var */_myLight: GTextFiled;

        /* internal */ /* var */_flyBoot: FlyFootBmp;

        /* internal */ /* var */_processNum: number;

        /* internal */ /* var */_process: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_processMask: Object /* flash.display.Shape */;

        /* internal */ /* var */_processHead: Object /* flash.display.Bitmap */;
    }
